<?php
	include_once 'json_function.php';
	if( !isset($_COOKIE["username"]) ){
		header("Location:login.php");
	}else{
		setcookie("username", $_COOKIE["username"],time() + 900);
	}
	
	$ini_array = parse_ini_file("config/config.ini");
	$conn = @mysqli_connect($ini_array["host"], $ini_array["username"], $ini_array["password"], $ini_array["db_name"]) or die("cann't connect the mysql db");
	mysqli_set_charset($conn, "utf8");
	ini_set('default_charset', "UTF-8");
	
	$clinicNo = mysqli_real_escape_string($conn,$_POST["clinicNo"]);
	//$clinicNo = 128760;
	
	
	
	
	
	$getClinicInfoSql = "select Clinic_name, Clinic_address, Clinic_detail from clinic where Clinic_no=".$clinicNo;
	$clinicResult = mysqli_query($conn, $getClinicInfoSql);
	
	$hasData = false;
	$data = "{\"data\":{";
	while( $row = mysqli_fetch_array($clinicResult) ){
		$hasData = true;
		$data .= "\"clinicNo\":\"".$clinicNo."\",";
		$data .= "\"clinicName\":\"".replaceQuoteAndSlash($row["Clinic_name"])."\",";
		$data .= "\"clinicAddress\":\"".replaceQuoteAndSlash($row["Clinic_address"])."\",";
		$data .= "\"clinicDetail\":\"".replaceQuoteAndSlash($row["Clinic_detail"])."\"";
	}
	
	if( $hasData == false ){
		$data .= "\"clinicNo\":\"".$clinicNo."\",";
		$data .= "\"clinicName\":\"\",";
		$data .= "\"clinicAddress\":\"\",";
		$data .= "\"clinicDetail\":\"\"";
	}
	$data .= "}}";
	

	//echo  json_encode($data);
	echo JsonCharFilter($data);
	//echo $data;
?>